package com.hzw.saas.web.sso.service;

import com.hzw.saas.web.sso.controller.dto.SsoTokenDto;
import com.hzw.saas.web.sso.exception.SaasOauthException;
import com.hzw.saas.web.sso.pojo.dto.CodeInfoDto;
import com.hzw.saas.web.sso.pojo.dto.TokenInfoDto;
import com.hzw.saas.web.sso.pojo.model.SaasClient;
import com.hzw.saas.web.sso.pojo.redis.SsoUser;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

/**
 * @author sonam
 * @sine 2021/11/9 5:06 下午
 */
public interface ISaasOauthService {

    /**
     * 校验客户端属性是否合法
     * @param client
     * @param redirectUri
     * @param scopes
     * @param responseType
     * @return
     * @throws SaasOauthException
     */
    void check(SaasClient client, String redirectUri, List<String> scopes, String responseType) throws SaasOauthException;


    /**
     * 获取授权码
     * @param saasClient
     * @param scopes
     * @param redirectUri
     * @param username
     * @param password
     * @return
     */
    CodeInfoDto getCode(SaasClient saasClient, List<String> scopes, String redirectUri, String username, String password) throws SaasOauthException;

    /**
     * 通过授权码拿到token
     * @param saasClient
     * @param clientSecret
     * @param code
     * @return
     */
    TokenInfoDto getTokenByCode(SaasClient saasClient, String clientSecret, String code) throws SaasOauthException;

    /**
     * 刷新token
     * @param saasClient
     * @param refreshToken
     * @return
     */
    TokenInfoDto refreshToken(SaasClient saasClient, String refreshToken) throws SaasOauthException;

    /**
     * 密码模式登录
     * @param saasClient
     * @param clientSecret
     * @param username
     * @param password
     */
    TokenInfoDto password(SaasClient saasClient, String clientSecret, String username, String password) throws SaasOauthException;

    /**
     * 构造token
     * @param user
     * @param password
     * @return
     */
    SsoTokenDto buildSsoToken(UserDetails user, String password);

    /**
     * 获取token
     * @param ssoToken
     * @return
     */
    SsoUser getSsoTokenInfo(String ssoToken);
}
